package executes;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;


import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import xls.Utils;

public class CreateHyperlinks
{

  /**
 * @author wed
 * Nothing done yet. I first create all 3D tours and will start with the passes200 3D hyperlinks. Take the existing hyperlinks and create 3d tours links out of it. Leave lnks in same sequence
   */
  public static void main(String[] args) {
    // TODO Auto-generated method stub
    try {
    	Workbook workbook = Workbook.getWorkbook(new File("C:\\XLS\\CTA.xls"));
    	Sheet sheet = workbook.getSheet(13);
    	Cell[] name = sheet.getColumn(0);
    	FileWriter fstream = new FileWriter("C:\\XLS\\hyperlinks.txt");
    	BufferedWriter textFile = new BufferedWriter(fstream);
       	for (int i = 0; i < name.length; i++) {
	        Cell latlngCell = sheet.getCell(0,i);
	        String hyperlink = latlngCell.getContents();
	        System.out.println(hyperlink);
	        textFile.write(hyperlink+ "\n");
	        i++;
       	}
       	for (int j = 0; j < name.length; j++) {
	        Cell latlngCell = sheet.getCell(0,j);
	        String hyperlink = latlngCell.getContents();
	        System.out.println(hyperlink);
	        String hyperlinkdescription = hyperlink.replaceAll("Cycling", "(3D Tour of").replaceAll("\"[)];", "-tour\");").replaceAll(" = ", "Tour = ");
	        textFile.write(hyperlinkdescription+ "\n");
	        j++;
       	}
       	for (int k = 0; k < name.length; k++) {
	        Cell latlngCell = sheet.getCell(0,k);
	        String hyperlink = latlngCell.getContents();
	        System.out.println(hyperlink);
	        String hyperlinkdescription = hyperlink.replaceAll("Cycling", "(Video of").replaceAll("\"[)];", "-video\");").replaceAll(" = ", "Video = ");
	        textFile.write(hyperlinkdescription+ "\n");
	        k++;
       	}
       	for (int l = 0; l < name.length; l++) {
	        Cell latlngCell = sheet.getCell(0,l);
	        String hyperlink = latlngCell.getContents();
	        System.out.println(hyperlink);
	        String hyperlinkdescription = hyperlink.replaceAll("Cycling", "(Slideshow of").replaceAll("\"[)];", "-slideshow\");").replaceAll(" = ", "Slideshow = ");
	        textFile.write(hyperlinkdescription+ "\n");
	        l++;
       	}


    	textFile.close();
    } catch (BiffException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}
